package com.ems.mapper;

import com.ems.entity.PcsEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ems.vo.PcsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * PCS数据 Mapper 接口
 * </p>
 *
 * @author WuZH
 * @since 2024-04-23
 */
@Mapper
public interface PcsMapper extends BaseMapper<PcsEntity> {

    @Select ( value = "SELECT * FROM pcs_info pi WHERE pi.id=#{pcsVo.id}")
    PcsVo querySingle ( @Param ( "pcsVo" ) PcsVo pcsVo );

    @Select ( value = "SELECT * FROM pcs_info pi\n" +
            "         JOIN (SELECT deviceAddress, max(createTime) AS createTime FROM pcs_info GROUP BY deviceAddress) pii\n" +
            "              ON pi.deviceAddress = pii.deviceAddress AND pi.createTime=pii.createTime\n" +
            "LEFT JOIN device_info di ON pi.deviceAddress=di.deviceAddress ORDER BY pi.createTime DESC" )
    List<PcsVo> queryList ( @Param ( "pcsVo" ) PcsVo pcsVo );

    @Select ( value = "SELECT COUNT(1) FROM pcs_info" )
    Integer queryCount ( @Param ( "pcsVo" ) PcsVo pcsVo );

}
